package com.jk.common.datasource;

/**
 * 使用ThreadLocal技术来记录当前线程中数据源的读写策略
 * Created by JK on 2017/6/21.
 */
public class DynamicDataSourceContextHolder {

    private static final ThreadLocal<RoutingStrategy> contextHolder = new ThreadLocal<>();

    /**
     * 设置数据源读写策略
     * @param customerType
     */
    public static void setDataSource(RoutingStrategy customerType) {
        contextHolder.set(customerType);
    }

    /**
     * 获取数据源读写策略
     * @return
     */
    public static RoutingStrategy getDataSource() {
        return (RoutingStrategy) contextHolder.get();
    }

    /**
     * 清除数据源读写策略
     */
    public static void clearDataSource() {
        contextHolder.remove();
    }
}
